{% extends "pos/base.html" %}

{% load staticfiles %}

{% block head %}
    <script type="text/javascript" src="{% static "js/jquery-1.7.2.min.js" %}"></script>
    <link type="text/css" rel="stylesheet" href="{% static "js/jquery-ui-1.8.23.custom/css/ui-lightness/jquery-ui-1.8.23.custom.css" %}"/>
    <script type="text/javascript" src="{% static "js/jquery-ui-1.8.23.custom/js/jquery-ui-1.8.23.custom.min.js" %}"></script>
    <script type="text/javascript" src="{% static 'js/bootstrap-2.3.2/js/bootstrap.min.js' %}"></script>
    <script type="text/javascript" src="{% static 'js/manage_projects.js' %}"></script>
{% endblock head %}


{% block content %}
    <!-- Area Container -->
    <div id="home_container" style="height: 550px; overflow-y:auto">

        <h2>Manage Projects</h2>
        {# Add any success/error feedback messages #}
        {% if messages %}
        <ul class="messages">
            {% for message in messages %}
            <h3><li{% if message.tags %} class="{{ message.tags }}"{% endif %}>{{ message }}</li></h3>
            {% endfor %}
        </ul>
        {% endif %}

        <table id="general" class="manage_projects_table">
            <tr>
                <th>Project Name</th>
                <th>Project Region</th>
                <th>View Stats</th>
                <th>Scenario Calculator</th>
            </tr>
            {% if no_projects %}
                <td>No projects have been created yet</td>
            {% else %}
                {% for project in projects %}
                    <tr>
                        <td>{{ project.project_name }}</td>
                        {% if project.region %}
                            <td align="center">
                                {% if 'SP' in project.region.type %}
                                    -
                                {% elif project.region.check_polygon %}
                                    <a href="{% url 'draw_user_region' project.region.pk %}">Edit</a> / <a href="{% url 'upload_user_region' project.region.pk %}">Upload</a>
                                {% else %}
                                    <a href="{% url 'draw_user_region' project.region.pk %}">Draw</a> / <a href="{% url 'upload_user_region' project.region.pk %}">Upload</a>
                                {% endif %}
                            </td>
                            <td align="center">
                                {% if project.region.check_polygon %}
                                    <a align="center" href="{% url 'load_region' project.region.pk %}">View</a>
                                {% else %}
                                    -
                                {% endif %}
                            </td>
                            <td align="center">
                                {% if project.region.check_polygon %}
                                    <a href="{% url 'scenario_modelling' project.pk %}">Edit</a>
                                {% else %}
                                    -
                                {% endif %}
                            </td>
                            <td align="center">
                                <a id="id_delete_project_link_{{ project.pk }}" class="project_delete_link" align="center" href="del">Delete</a>
                                <div>
                                    <form method='POST' enctype='multipart/form-data' action='{% url "delete_project" %}'>
                                        {% csrf_token %}
                                        <input type="hidden" name="project_pk" value="{{ project.pk }}"/>
                                        <input class="btn btn-info" id="id_submit_delete_button_{{ project.pk }}" type="submit" value="Confirm" style="display: none;" title="Click 'Confirm' if you want to delete this project"/>
                                        <input class="btn btn-danger project_cancel_delete" id="id_cancel_delete_button_{{ project.pk }}" type="button" value="Cancel" style="display: none;" title="Click 'Cancel' if you do not want to delete this project"/>
                                    </form>
                                </div>
                            </td>
                        {% else %}
                            <td align="center">No Region</td>
                            <td align="center">No Stats</td>
                            <td align="center">No Scenario Modelling</td>
                        {% endif %}
                    </tr>
                {% endfor %}
            {% endif %}
        </table>
        <fieldset>
            <form method="POST" action="{% url 'pos.views.project.add_project' %}">
            {% csrf_token %}
                <input type="submit" name="add_project" value="Add Project">
            </form>
        </fieldset>
    </div>

{% endblock content %}
